package cn.wzvtcsoft.base;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author swxu_2005@163.com
 * 自定义接口 不会创建接口的实例  必须加此注解
 */
@NoRepositoryBean
public interface BaseRepository<E, ID> extends JpaRepository<E, ID>, JpaSpecificationExecutor<E> {

  @Transactional(rollbackFor = Exception.class)
  @Modifying
  @Query("update #{#entityName} e set e.deleted=1 where e.id=?1")
  int softDelete(Long id);

  @Transactional(rollbackFor = Exception.class)
  @Modifying
  @Query("update #{#entityName} e set e.deleted=1 where e.id in ?1")
  int softDeleteAll(List<Long> ids);

}
